//导入封装好的axios
import instance from '@/utils/axios.js'


//1、请求频道列表

function channelsList() {
    return instance({
        url: '/v1_0/channels',
        method: 'get'
    })
}
export { channelsList }


//2、获取文章列表
function articleList({ channel_id, timestamp }) {
    return instance({
        url: '/v1_1/articles',
        method: 'get',
        params: {
            with_top: 1, //是否需要置顶，给1即可
            channel_id,
            timestamp
        }
    })
}


export { articleList }


//3.获取文章详情
function getArticle({ id }) {
    return instance({
        url: '/v1_0/articles/' + id,
        method: 'get'
    })
}

export { getArticle }

//4、关注用户接口
function followdeUser({ target }) {
    return instance({
        url: "/v1_0/user/followings",
        method: 'post',
        data: {
            target
        }
    })
}
export { followdeUser }


//5、取消关注
function unfollowdeUser(target) {
    return instance({
        url: '/v1_0/user/followings/' + target,
        method: 'DELETE'
    })
}

export { unfollowdeUser }


//6、文章点赞
function articleParise({ target }) {
    return instance({
        url: "/v1_0/article/likings",
        method: 'post',
        data: {
            target
        }
    })
}
export { articleParise }


//7、取消点赞
function unarticleParise(target) {
    return instance({
        url: '/v1_0/article/likings/' + target,
        method: 'DELETE'
    })
}

export { unarticleParise }

//8、获取搜索结果
function getSearch({ page, per_page, q }) {
    return instance({
        url: '/v1_0/search',
        method: 'get',
        params: {
            page,
            per_page,
            q
        }
    })
}
export { getSearch }
//9、模糊搜索
function getSuggestion({ q }) {
    return instance({
        url: '/v1_0/suggestion',
        method: 'get',
        params: {
            q
        }
    })
}
export { getSuggestion }

//10.对文章不喜欢
function getDislike({ target }) {
    return instance({
        url: '/v1_0/article/dislikes',
        method: 'post',
        data: {
            target
        }
    })

}

export { getDislike }

//11、对文章取消不喜欢
function getLike(target) {
    return instance({
        url: '/v1_0/article/dislikes/' + target,
        method: 'DELETE',
    })

}
export { getLike }

//搜索历史
function searchHistory() {
    return instance({
        url: '/v1_0/search/histories',
        method: 'get',
    })

}
export { searchHistory }


//删除搜索历史
function delSearchHistory() {
    return instance({
        url: '/v1_0/search/histories',
        method: 'DELETE',
    })

}
export { delSearchHistory }